#include "stdafx.h"
#include "ShaderEffect.h"

using namespace MomogenkyouSystem;

EffectParameter::EffectParameter()
:	m_pParentEffect(NULL)
,	m_Name("")
,	m_Handle(NULL)
{
}

EffectParameter::EffectParameter(SHADEREFFECT Parent, const std::string & Name)
:	m_pParentEffect(Parent), m_Name(Name.c_str()), m_Handle(NULL)
{
	m_Handle = m_pParentEffect->GetParameterByName(m_Handle, Name.c_str());
	ASSERT(m_Handle != NULL, "Effect Parameter not found");
}

EffectParameter::~EffectParameter()
{
	m_pParentEffect = NULL;
	m_Handle = NULL;
}

Shader::Shader()
:	Effect(NULL)
{

}

Shader::~Shader()
{
	Effect->Release();
}


EffectParameter Shader::GetParameter(const std::string & ParamName)
{
	return EffectParameter(Effect, ParamName);
}

bool Shader::Prepare(const std::string & Filename)
{
	HRESULT Result = D3DXCreateEffectFromFileA(GraphicsSystem::Device, 
		Filename.c_str(), NULL, NULL, NULL, NULL, &Effect, NULL);
	ASSERT(Result == S_OK && Effect != NULL, "Unable to create Effect from file");
	if(Result != S_OK) return false;
	return true;
}